<%@page import="java.util.List"%>
<%@ page import="dao.AdminDAO" %>
<%@ page import="bean.Admin" %>
<%@ page contentType="text/html;charset=UTF-8" language="java"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>新闻管理</title>
    <link rel="stylesheet" type="text/css" href="../../css/Iframe.css" />
    <link rel="stylesheet" type="text/css"
          href="../../css/bootstrap.min.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="../../css/layui.css" />
</head>

<body>
<%
    if ((session.getAttribute("admin") != null) && !("true".equals((String) session.getAttribute("refresh")))) {
        out.print("<script>parent.location.reload();</script>");
        session.setAttribute("refresh", "true");
    }
    String currentPage = request.getParameter("currentPage");
    if (currentPage == null) {
        currentPage = "1";
    }
    AdminDAO dao = new AdminDAO();
    //总新闻数
    int allRecords = dao.getAllRecords();
    //总页数
    int allPage = dao.getTotalPage(allRecords);
    //当前页面新闻内容
    int currentPageInt = Integer.parseInt(currentPage);
    if (currentPageInt < 1) {
        currentPageInt = 1;
        out.print("<script>alert('已经是第一页了！')</script>");
    } else if (currentPageInt > allPage) {
        currentPageInt = allPage;
        out.print("<script>alert('已经是最后一页了！')</script>");
    }
    List<Admin> list = dao.getCurrentPageNews(currentPageInt);
    session.setAttribute("adminList", list);
%>
<span class="cp_title">用户管理</span>
<div class="add_cp">
    <a href="adminAdd.jsp?currentPage=<%=currentPageInt%>">+添加用户</a>
</div>
<div class="table_con">
    <div class="table_con">
        <table>
            <tr class="tb_title">
                <td width="10%">ID</td>
                <td width="10%">账户</td>
                <td width="10%">密码</td>
                <td width="20%">名字</td>
                <td width="10%">性别</td>
                <td width="10%">管理员</td>
                <td width="10%">操作</td>
            </tr>
            <%
                for (int i = 0; i < list.size(); i++) {
            %>
            <tr>
                <td width="10%"><%=list.get(i).getId()%></td>
                <td width="10%"><%=list.get(i).getAccount()%></td>
                <td width="10%"><%=list.get(i).getPwd()%></td>
                <td width="20%"><%=list.get(i).getName()%></td>
                <td width="10%"><%=list.get(i).getSex()%></td>
                <td width="10%"><%=list.get(i).getAdmin()?"是":"否"%></td>
                <td width="13%"><a
                        href="/News/GetByID?index=<%=i%>&currentPage=<%=currentPageInt%>"
                        class="del_btn">编辑</a> &nbsp; <a
                        href="/News/Delete?id=<%=list.get(i).getId()%>&currentPage=<%=currentPageInt%>"
                        class="del_btn">删除</a></td>
            </tr>
            <%
                }
            %>
        </table>
        <div style="text-align: center">
            一共有<%=allRecords%>条记录，共<%=allPage%>页，当前第<%=currentPageInt%>页&nbsp;
        </div>
        <br>
        <div style="text-align: center">
            <ul class="pagination">
                <li><a href="usersList.jsp?currentPage=1">首页</a></li>
                <li><a
                        href="usersList.jsp?currentPage=<%=currentPageInt - 1%>">上一页</a></li>
                <li><a
                        href="usersList.jsp?currentPage=<%=currentPageInt + 1%>">下一页</a></li>
                <li><a href="usersList.jsp?currentPage=<%=allPage%>">尾页</a></li>
            </ul>
        </div> <br>
    </div>
</div>
</body>
</html>

